<?php
namespace App\Service\Pays\Alipay;

use Yurun\PaySDK\AlipayApp\App\Params\Pay\Request;

class App
{
    protected $service;
    
    protected $request;
    
     // 创建
    public function __construct($service)
    {
        $this->service = $service;
        $this->request = new Request;
    }
    
    // 传入名称
    public function setTitle($title)
    {
        $this->request->businessParams->subject = $title;
        
        return $this;
    }
    
    // 订单号
    public function setOrderId($order_id)
    {
        $this->request->businessParams->out_trade_no = $order_id . '_' . $this->service->getRand(20);
         
        return $this;
    }
    
    // 支付金额
    public function setMoney($money)
    {
        $this->request->businessParams->total_amount = $money;
        
        return $this;
    }
    
    // 回调地址
    public function setNotify($url)
    {
        $this->request->notify_url = $url;
        
        return $this;
    }
    
    // 服务商模式
    public function service()
    {
        $this->request->businessParams->extend_params->sys_service_provider_id = $this->service->service();
        
        return $this;
    }
    
    // 提交
    public function send()
    {
        $this->service->sdk->prepareExecute($this->request, $url, $data);

        return http_build_query($data);
    }
}